home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
133_01
/
e1
< prev
next >
Wrap
Text File
|
1985-03-09
|
7KB
|
295 lines
/*
e screen editor
(C) G. Nigel Gilbert, MICROLOGY, 1981
August-December 1981
FILE: e1
FUNCTIONS: printdirectory, envir, files, putonoff, putxy, getnumb
PURPOSE: environment; change files.
*/
#include "e.h"
#define EXTENT 12
#define D0 16
#define DN 31
printdirectory(drive)
int drive;
{
int y, *dsm, *drm, cols, i;
unsigned blsr, used;
char c, pos, entriesonline, fcb[36], *bsh;
sint userno, dmabuf[128], *entry;
putclr();
if (errmess != NULL) {
gotoxy(EMPOS,0);
puts(errmess);
}
bdos(SETDMA,dmabuf);
gotoxy(0,6);
puts("Directory of ");
putch(drive+'A');
putch(':');
if (userno=bdos(USERCODE,0xff)) {
puts(" (user ");
uspr(userno);
puts(") ");
}
if (curdsk != drive && seldisk(drive) != FAIL) {
puts(" |(default drive is ");
putch(curdsk+'A');
puts(":|)");
}
setfcb(fcb,"*.*");
fcb[0]='?';
used=0;
bsh=bdos(DSKPARAMS)+2;
dsm=bsh+3;
drm=dsm+1;
blsr= (1 << *bsh)/8; /*block size in kbytes*/
entriesonline=0;
makedim();
deleteline(2,(y=8));
pos=bdos(SEARCH1,fcb);
while (pos != 0xff) {
if (inbufp) {
puts(" ...");
goto incomplete;
}
entry= &dmabuf[pos << 5];
if (*entry < 16)
for (i=D0; i <= DN; i++)
if (*(entry+i)) used+=blsr;
if (*entry == userno && *(entry+EXTENT) <= 1) {
for (i=1, cols=0; i < 12; i++) {
c= *(entry+i) & 0x7f;
if (i == 9 && c != ' ') {
cols++;
putch('.');
}
if (c != ' ') {
cols++;
putch( (i >= 9 ? tolower(c) : c));
}
}
while (cols++ < 12) putch(' ');
if (++entriesonline == 5) {
deleteline(2,++y);
if (y == SHEIGHT) {
puts("|etc");
goto incomplete;
}
entriesonline=0;
}
else puts(" : ");
}
pos=bdos(SEARCHN,fcb);
}
gotoxy(50,SHEIGHT);
puts("Free space = ");
uspr(((*dsm+1)*blsr-(*drm+1)/32)-used);
putch('k');
incomplete:
if (curdsk != drive) seldisk(curdsk);
makebright();
gotoxy(0,0);
}
#define XTEXT 10
#define XVAL 42
#define XPROMPT 63
#define YTITLE 4
#define YFILE 6
#define YAUTO 8
#define YBACKUP 9
#define YTAB 10
#define YSTRIP 11
#define YCURSOR 12
#define YSCROLL 13
#define YHILITE 14
#define YPROMPT 16
#define YSPACE 22
envir()
{
char c, getlow();
struct addr anaddr;
puttext();
putclr();
putstatusline(cline);
putxy(YTITLE,"Edit context:");
putxy(YFILE," |enter |F| for file context");
putxy(YAUTO,"A|uto indent:");
putonoff(YAUTO,autoin);
putxy(YBACKUP,"|make |B|ackup of original file:");
putonoff(YBACKUP,backup);
putxy(YTAB,"T|ab stops every");
gotoxy(XVAL,YTAB);
uspr(tabwidth);
putxy(YSTRIP,"S|trip trailing blanks,tabs");
putonoff(YSTRIP,!trail);
putxy(YCURSOR,"|display cursor |L|ine and column");
putonoff(YCURSOR,displaypos);
putxy(YSCROLL,"H|orizontal scroll whole screen");
putonoff(YSCROLL,blockscroll);
putxy(YHILITE,"|h|I|ghlight cursor line");
putonoff(YHILITE,hilight);
putxy(YSPACE,"|Memory allows for no more than ");
uspr( (slotsinmem-2)*PAGESIZE/sizeof(anaddr) );
puts("| lines of text");
putxy(YPROMPT,"Enter a letter, or [return] to exit:");
do {
gotoxy(XPROMPT,YPROMPT);
switch((c=getlow())) {
case 'a':
putonoff(YAUTO,(autoin= !autoin));
break;
case 'b':
putonoff(YBACKUP,(backup= !backup));
break;
case 't':
putxy(YTAB,"|Enter new |tab width|:");
gotoxy(XVAL,YTAB);
puts(" ");
gotoxy(XVAL,YTAB);
tabwidth=getnumb();
putxy(YTAB,"T|ab stops every ");
break;
case 'l':
putonoff(YCURSOR,(displaypos=!displaypos));
break;
case 'h':
putonoff(YSCROLL,(blockscroll=!blockscroll));
break;
case 's':
putonoff(YSTRIP,!(trail=!trail));
break;
case 'i':
putonoff(YHILITE,(hilight=!hilight));
break;
case 'f':
files();
case 'q':
case 'm':
case ESCKEY:
goto escape;
}
}
while (YES);
escape:
putclr();
topline=1;
if (helpon) dohelp();
putpage();
}
files()
{
char oldname[FILELEN], newname[FILELEN], c, getlow();
int dir, warn;
dir=curdsk;
do {
printdirectory(dir);
putstatusline(cline);
newcomm:
errmess=NULL;
gotoxy(0,1);
puts("|Enter |[return]| to exit |D| to delete a file\n");
puts(" R| to rename a file |V| to view another directory \n");
deleteline(0,3);
puts(" C| to change the name of the edited file ");
puts(filename);
deleteline(0,4);
deleteline(0,5);
gotoxy(6,4);
c=getlow();
putstatusline(cline);
deleteline(6,4);
if (c == 'r' || c == 'd' || c == 'c') {
puts("Name of file: ");
scans(oldname,FILELEN);
if (!oldname[0]) goto newcomm;
format(oldname);
}
switch (c) {
case 'm':
case 'q':
case ESCKEY:
return;
case 'v':
puts("Enter drive letter |(A to P): ");
if ( (dir=getkey()) == CR ||
(dir=tolower(dir)-'a') < 0 || dir >= 16)
dir=curdsk;
continue;
case 'd':
if (funlink(oldname) == FAIL) {
error("Can't delete");
goto newcomm;
}
break;
case 'r' :
deleteline(6,5);
puts("New name: ");
scans(newname,FILELEN);
format(newname);
if (!newname[0] || frename(oldname,newname) == FAIL) {
error("Can't rename");
goto newcomm;
}
break;
case 'c' :
strcpy(filename,oldname);
putstatusline(cline);
default:
goto newcomm;
}
}
while (YES);
}
putxy(row,string)
int row;
char *string;
{
gotoxy(XTEXT,row);
puts(string);
}
putonoff(row,flag)
int row,flag;
{
gotoxy(XVAL,row);
puts((flag?"ON ":"OFF"));
}
getnumb()
{
int i, n;
char c, numb[5];
scans(numb,5);
n=0;
for (i=0; (c=numb[i]); i++)
if (c >= '0' && c <= '9') n=n*10+c-'0';
return n;
}
case ESCKEY:
goto escape;
}
}